package com.amado.course42Socket.tcp.homework;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * Created by Administrator on 2018/8/7.
 */
public class FileCopyClient {
	private int port = 8888;
	private Socket socket;

	public FileCopyClient() throws Exception {
		socket = new Socket("192.168.0.99",port);
		System.out.println("服务器启动!");
	}

	public void service() {
		InputStream inputStream = null;
		try {
			System.out.println(socket.getInetAddress() + "  " + socket.getPort());
			//开启一个线程去读取对方的聊天的信息
			OutputStream outputStream = socket.getOutputStream();
			inputStream = new FileInputStream(new File("F:\\awt框架图片\\1.png"));
			byte[] content = new byte[1024];
			int len =0;
			while((len=inputStream.read(content))!=-1) {
				outputStream.write(content, 0, len);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				inputStream.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		System.out.println("发送成功");

	}

	public static void main(String[] args) throws Exception {
		FileCopyClient server = new FileCopyClient();
		server.service();
	}
}
